/*
 * To change this template, choose Tools | Templates
 * and open the template in the editor.
 */
package com.openbrew.openbrewrf;

import java.io.Serializable;
import java.util.Date;
import java.util.List;
import javax.persistence.Basic;
import javax.persistence.CascadeType;
import javax.persistence.Column;
import javax.persistence.Entity;
import javax.persistence.GeneratedValue;
import javax.persistence.GenerationType;
import javax.persistence.Id;
import javax.persistence.JoinColumn;
import javax.persistence.JoinTable;
import javax.persistence.NamedQueries;
import javax.persistence.NamedQuery;
import javax.persistence.OneToMany;
import javax.persistence.Table;
import javax.persistence.Temporal;
import javax.persistence.TemporalType;
import javax.validation.constraints.NotNull;
import javax.xml.bind.annotation.XmlRootElement;
import org.eclipse.persistence.annotations.CascadeOnDelete;

/**
 *
 * @author chapmand
 */
@Entity
@Table(name = "PurchaseOrder")
@XmlRootElement
@NamedQueries({
    @NamedQuery(name = "PurchaseOrder.findAll", query = "SELECT p FROM PurchaseOrder p"),
    @NamedQuery(name = "PurchaseOrder.findNewPOs", query = "SELECT p FROM PurchaseOrder p WHERE p.pOState < '10'"),
    @NamedQuery(name = "PurchaseOrder.findApprovedPOs", query = "SELECT p FROM PurchaseOrder p WHERE p.pOState < '20'"),
    @NamedQuery(name = "PurchaseOrder.findOrderedPOs", query = "SELECT p FROM PurchaseOrder p WHERE p.pOState < '30'"),
    @NamedQuery(name = "PurchaseOrder.findReceivedPOs", query = "SELECT p FROM PurchaseOrder p WHERE p.pOState >= '30'"),
    @NamedQuery(name = "PurchaseOrder.findByPoid", query = "SELECT p FROM PurchaseOrder p WHERE p.poid = :poid"),
    @NamedQuery(name = "PurchaseOrder.findByPOState", query = "SELECT p FROM PurchaseOrder p WHERE p.pOState = :pOState"),
    @NamedQuery(name = "PurchaseOrder.findByPODate", query = "SELECT p FROM PurchaseOrder p WHERE p.pODate = :pODate"),
    @NamedQuery(name = "PurchaseOrder.findByExported", query = "SELECT p FROM PurchaseOrder p WHERE p.exported = :exported"),
    @NamedQuery(name = "PurchaseOrder.findOpenPOs", query = "SELECT p FROM PurchaseOrder p WHERE p.pOState != '30'"),
    @NamedQuery(name = "PurchaseOrder.findOnOrderPOs", query = "SELECT p FROM PurchaseOrder p WHERE p.pOState = '20'")})
public class PurchaseOrder implements Serializable {
    private static final long serialVersionUID = 1L;
    @Id
    @GeneratedValue(strategy = GenerationType.IDENTITY)
    @Basic(optional = false)
    @Column(name = "POID")
    private Integer poid;
    @Basic(optional = false)
    @NotNull
    @Column(name = "POState")
    private int pOState;
    @Basic(optional = false)
    @NotNull
    @Column(name = "PODate")
    @Temporal(TemporalType.DATE)
    private Date pODate;
    @Basic(optional = false)
    @NotNull
    @Column(name = "exported")
    private boolean exported;
    @OneToMany(cascade=CascadeType.ALL, orphanRemoval = true)
    @CascadeOnDelete
    @JoinTable(
        name="JTPOrders",
        joinColumns={ @JoinColumn(name="POID", referencedColumnName="POID")},
        inverseJoinColumns={ @JoinColumn(name="POLID", referencedColumnName="POLID", unique=true)}
    )
    private List<POLines> poLinesCollection;

    public PurchaseOrder() {
    }

    public PurchaseOrder(Integer poid) {
        this.poid = poid;
    }

    public PurchaseOrder(Integer poid, int pOState, Date pODate, boolean exported) {
        this.poid = poid;
        this.pOState = pOState;
        this.pODate = pODate;
        this.exported = exported;
    }

    public Integer getPoid() {
        return poid;
    }

    public void setPoid(Integer poid) {
        this.poid = poid;
    }

    public int getPOState() {
        return pOState;
    }

    public void setPOState(int pOState) {
        this.pOState = pOState;
    }

    public Date getPODate() {
        return pODate;
    }

    public void setPODate(Date pODate) {
        this.pODate = pODate;
    }

    public boolean getExported() {
        return exported;
    }

    public void setExported(boolean exported) {
        this.exported = exported;
    }

    public List<POLines> getPOLinesCollection() {
        return poLinesCollection;
    }

    public void setPOLinesCollection(List<POLines> poLinesCollection) {
        this.poLinesCollection = poLinesCollection;
    }

    @Override
    public int hashCode() {
        int hash = 0;
        hash += (poid != null ? poid.hashCode() : 0);
        return hash;
    }

    @Override
    public boolean equals(Object object) {
        // TODO: Warning - this method won't work in the case the id fields are not set
        if (!(object instanceof PurchaseOrder)) {
            return false;
        }
        PurchaseOrder other = (PurchaseOrder) object;
        if ((this.poid == null && other.poid != null) || (this.poid != null && !this.poid.equals(other.poid))) {
            return false;
        }
        return true;
    }

    @Override
    public String toString() {
        return "com.openbrew.openbrewrf.PurchaseOrder[ poid=" + poid + " ]";
    }
    
}
